<?php
namespace app\store\controller\market;
use app\store\controller\Controller;
use app\store\model\Winad as WinadModel;



/**
 * 广告控制器
 * Class Clerk
 * @package app\store\controller\marke\winad
 */
class Winad extends Controller
{
    /**
     * 
     * @param int $ad_id
     * @param string $search
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function index()
    {
      $model = WinadModel::detail();
      if($model) { 
			if (!$this->request->isAjax()) {
				return $this->fetch('index', compact('model'));
			}
			// 更新记录
			if ($model->index($this->postData('win_ad'))) {
				return $this->renderSuccess('更新成功', url('market.winad/index'));
			}
			return $this->renderError($model->getError() ?: '更新失败');
		  }else{
		    if (!$this->request->isAjax()) {
            return $this->fetch('add');
            }
			 // 新增记录
			$this->model = new WinadModel;
			if ($this->model->add($this->postData('win_ad'))) {
				return $this->renderSuccess('添加成功', url('market.winad/index'));
			}
			return $this->renderError($this->model->getError() ?: '添加失败');
	  }
    }
}